<?php

session_start();

if(array_key_exists("user", $_SESSION) && array_key_exists("email", $_SESSION)){
	switch($_SESSION['account']){
		case 1:
			header("Location: /a/main.php");
			exit;
			break;
		case 2:
			header("Location: /b/main.php");
			exit;
			break;
		case 3:
			header("Location: /c/main.php");
			exit;
			break;
	}
}

if(array_key_exists("username", $_POST) && array_key_exists("password", $_POST)){
	
	include_once "class/login.php";
	$login = new login();
	$valid = $login->loginCheck($_POST['username'], sha1($_POST['password']));
	
	if($valid == true){
		switch($_SESSION['account']){
			case 1:
				header("Location: /a/main.php");
				exit;
				break;
			case 2:
				header("Location: /b/main.php");
				exit;
				break;
			case 3:
				header("Location: /c/main.php");
				exit;
				break;
		}
	} else {
		$message = "Username and password combinations are not valid, please verify";
	}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE EDUCATION | Log In</title>
<link rel="stylesheet" type="text/css" href="/css/style-student.css" />
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35230372-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#000000"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="350" height="30" valign="bottom">&nbsp;</td>
        <td align="right" valign="bottom"><a href="/common/about.php" class="top-menu" style="color:#999">ABOUT</a> <a href="/common/contact-us.php" class="top-menu" style="color:#999">CONTACT US</a> <a href="/common/jobs.php" class="top-menu" style="color:#999">JOBS</a> <a href="/login.php" class="top-menu" style="color:#999">SIGN IN</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" style="background-image:url(images/top-bg-student.png); background-repeat:repeat-x">&nbsp;</td>
  </tr>
  <tr>
    <td height="550" align="center" valign="top"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top" align="center"><img src="images/login-header.png" width="680" height="100" alt="Log into pie.edu" /></td>
      </tr>
      <tr>
        <td><form id="loginForm" name="loginForm" method="post" action="/login.php" onsubmit="return loginValidation();">
      <table width="320" border="0" align="center" cellpadding="0" cellspacing="0" style="padding-top:80px">
        <?php
		if(isset($message)){
        echo '<tr>
          <td style="color:#F00" align="center" height="40"><strong>'.$message.'</strong></td>
        </tr>';
		}
        ?>
        <tr>
          <td><label for="username">Type your username</label>
            <input name="username" type="text" class="form" id="username" tabindex="1" /></td>
        </tr>
        <tr>
          <td><label for="password">Type your password</label>
            <input name="password" type="password" class="form" id="password" tabindex="2" /></td>
        </tr>
        <tr>
          <td valign="top"><a href="/common/recover.php" style="font-size:12px">Forgot your username or password?</a></td>
        </tr>
        <tr>
          <td height="40"><input name="enviar" type="submit" class="submit" id="enviar" value="Log In" /></td>
        </tr>
        </table>
    </form></td>
        </tr>
    </table></td>
  </tr>
</table>
<div id="bottom-div" align="center">PIE.EDU All Rights Reserved 2012<br />
      <a href="/common/privacy.php" class="bottom-menu" style="color:#999">Privacy Policy</a> | <a href="/common/terms.php" class="bottom-menu"  style="color:#999">Terms of Use</a> | <a href="/help/main.php" class="bottom-menu" style="color:#999">Help Center</a> | <a href="/common/jobs.php" class="bottom-menu" style="color:#999">Jobs</a></div>
</body>
</html>